package com.yass.zaika;
 

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.SparseBooleanArray;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.ListView;


public class Ingredient extends Activity implements TextWatcher{
	private Zaika application;
	
	Button submit;
    ListView listView;
    
    ItemAdapter adapter_list_view;
    ArrayAdapter<String> adapter_text_view;
    
    List<Item> ingredient_list2 = new ArrayList<Item>(28);
    List<String> ingredient_list = new ArrayList<String>(28);
    AutoCompleteTextView ing_text;
    
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ingredient_form);
		
		application = (Zaika) getApplication();
		application.instantiate();
		
		findViewsById();
		popIngredients();
		setList();
		
        
	}

public void clickButton(View v)
{
	/*
	switch(v.getId())
	{
		case R.id.submit:{
			SparseBooleanArray pos = listView.getCheckedItemPositions();
			for(int i = 0; i < pos.size();i++)
			{
				if(pos.get(i))
					application.getInput().addIngredients(adapter_list_view.getItem(i));
			}
			
			Intent myIntent = new Intent(Ingredient.this, MealTypeTime.class);
        	Ingredient.this.startActivity(myIntent);
		}
	}
	*/
}
private void setList()
{
	adapter_list_view = new ItemAdapter(this,ingredient_list2,ingredient_list);
	
	listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    listView.setAdapter(adapter_list_view);
    
    adapter_text_view = new ArrayAdapter<String>(this,
    		android.R.layout.simple_dropdown_item_1line,ingredient_list);
    ing_text.setThreshold(1);
    ing_text.setAdapter(adapter_text_view);
    ing_text.addTextChangedListener(this);
    
}

private void findViewsById() {
  listView = (ListView) findViewById(R.id.list);
  submit = (Button) findViewById(R.id.submit);
  ing_text = (AutoCompleteTextView)findViewById(R.id.ingredient_text);
}

private void popIngredients()
{
	ingredient_list.add("Salt");
	ingredient_list.add("Sugar");
	ingredient_list.add("Milk");
	ingredient_list.add("Butter");
	ingredient_list.add("Potatoes");
	ingredient_list.add("Bread");
	ingredient_list.add("Cheese");
	ingredient_list.add("Ham");
	ingredient_list.add("Hot dog bun");
	ingredient_list.add("Mustard");
	ingredient_list.add("Pickle");
	ingredient_list.add("Onion");
	ingredient_list.add("Tomatoes");
	ingredient_list.add("Pepper");
	ingredient_list.add("Egg");
	ingredient_list.add("Water");
	ingredient_list.add("Vegetable oil");
	ingredient_list.add("White rice");
	ingredient_list.add("Soy sauce");
	ingredient_list.add("Chicken");
	ingredient_list.add("Salmon");
	ingredient_list.add("Brown sugar");
	ingredient_list.add("Guacamole");
	ingredient_list.add("Cream cheese");
	ingredient_list.add("Lettuce");
	ingredient_list.add("Bacon");
	ingredient_list.add("Pizza dough");
	ingredient_list.add("Olive oil");
	ingredient_list.add("Basil leaves");
	Collections.sort(ingredient_list);
	
	for(int i = 0; i < ingredient_list.size();i++)
		ingredient_list2.add(new Item(ingredient_list.get(i), false));
}

@Override
public void afterTextChanged(Editable arg0) {
	// TODO Auto-generated method stub
	
}

@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
	// TODO Auto-generated method stub
	
}

@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
	String suggestion = ing_text.getText().toString().toLowerCase();
	adapter_list_view.getFilter().filter(suggestion);
}


}



